{include file='admin/before_body.phtml' title='后台首页'}
{include file='admin/header.phtml'}
    <div class="main-container" id="main-container">
      <script type="text/javascript">try { ace.settings.check('main-container' , 'fixed') }catch(e) {  }</script>
      <div class="main-container-inner">
        {include file='admin/sidebar.phtml' navigation='dashboard'}
        <div class="main-content">
{$breadcrumbs=[]}
{$breadcrumbs[] = ['name' => '店铺设置', 'icon' => 'icon-home home-icon']}
{$breadcrumbs[] = ['name' => '商品管理', 'link' => url('admin/user')]}
{$breadcrumbs[] = ['name' => '新增商品', 'isactive' => true]}
{include file='admin/breadcrumb.phtml' breadcrumbs=$breadcrumbs}
{$addItem = $smarty.session['addItem']['data']|default:null}
{$cate = $smarty.session['addItem']['cate']|default:null}
          <div class="page-content">
            {html_messages}
            <div class="row">
<div class="col-xs-12">
  <div class="user-profile row">
    <div class="col-xs-12 col-sm-offset-2 col-sm-3 center">
      <div>
        <span class="profile-picture">
          <img id="image" class="editable img-responsive" src="{$addItem['image']|default:urlStatic('images/picture_add.jpg')}" />
        </span>
      </div>
    </div>
    <div class="col-xs-12 col-sm-7">
      <form class="form-horizontal" cate="form" id="addform" method="POST">
        <input type="text" name="image" id="imageback" hidden value="{$addItem['image']|default:''}">
        <div class="form-group">
          <label class="col-sm-2 control-label no-padding-right"> 商品标题 </label>
          <div class="col-sm-10">
            <input type="text" class="col-xs-12 col-sm-6" name="name" value="{$addItem['name']|default:''}">
          </div>
        </div>
        <div class="space-4"></div>
        <div class="form-group">
          <label class="col-sm-2 control-label no-padding-right"> 商品描述 </label>
          <div class="col-sm-10">
            <textarea class="col-xs-12 col-sm-6 autosize-transition" name="describe">{$addItem['describe']|default:''}</textarea>
          </div>
        </div>
        <div class="space-4"></div>
        <div class="form-group">
          <label class="col-sm-2 control-label no-padding-right"> 消耗时长 </label>
          <div class="col-sm-10">
            <input type="text" name="lifetime" class="input-mini" vaule="{$addItem['lifetime']|default:''}" id="lifetime" />
            (分钟)
          </div>
        </div>
        <div class="space-4"></div>
        <div class="form-group">
          <label class="col-sm-2 control-label no-padding-right"> 鲜花收益 </label>
          <div class="col-sm-10">
            <input type="text" name="flowers" class="input-mini" vaule="{$addItem['flowers']|default:''}" id="flowers" />
            (朵)
          </div>
        </div>
        <div class="space-4"></div>
        <div class="form-group">
          <label class="col-sm-2 control-label no-padding-right"> 状态 </label>
          <div class="col-sm-10">
            <input class="ace ace-switch ace-switch-7" value='1' name="status" type="checkbox" {if
              $addItem['status']|default:'' == '1'
            } checked="checked" {/if} />
            <span class="lbl"></span>
          </div>
        </div>
        <div class="space-4"></div>
        <div class="form-group">
          <label class="col-sm-2 control-label no-padding-right"> 分类 </label>
          <div class="col-sm-10">
            <select id="cateid" name="cate_id" class="col-xs-12 col-sm-6">
              {if isset($cate)}
                <option value="{$cate['cate_id']}">{$cate['catename']}</option>
              {/if}
              <option value=""></option>
            </select>
          </div>
        </div>
        <div class="clearfix form-actions" style="background: none;border-top: none;">
          <div class="col-md-offset-2 col-md-10">
            <button class="btn" type="reset"><i class="icon-undo bigger-110"></i>重置</button>
            <button class="btn btn-info" type="submit">
              <i class="icon-edit bigger-110"></i> 新增
            </button>
          </div>
        </div>
      </form>
    </div>
  </div>
</div>
</div><!-- /.col -->
            </div>
          </div>
        </div>
      </div>
    </div>
</body>
{include file='admin/after_body.phtml'}
{include file='admin/upload_image.phtml' showid="image" callbackid="imageback" btnchoose="上传商品图片" type="storeitem"}
<script type="text/javascript">
  $('textarea[class*=autosize]').autosize({ append: "\n" });
  $('#flowers').ace_spinner({ value:0,min:0 ,step:1, on_sides: true, icon_up:'icon-plus smaller-75', icon_down:'icon-minus smaller-75', btn_up_class:'btn-success' , btn_down_class:'btn-danger' });
  $('#lifetime').ace_spinner({ value:0,min:0 ,step:10, on_sides: true, icon_up:'icon-plus smaller-75', icon_down:'icon-minus smaller-75', btn_up_class:'btn-success' , btn_down_class:'btn-danger' });

  $('#addform').on('reset', function() {
    $('input[name="image"]').val('');
    $('input[name="image"]').change();
  });

$('#cateid').select2(LIVE.component.select2.config({
  placeholder: '请选择一个商品分类',
  ajax: {
    url : '{url('admin/store/cate')}',
    data: function(params) {
      return { search: params.term, page: params.page };
    },
    processResults: function (res, params) {
      params.page = params.page || 1;
      var data = res.result;
      return {
        results: data.list.map(function(cate) { return { id: cate.cate_id, text: cate.name } }),
        pagination: { more: data.next }
      };
    },
  },
  language: { 'noResults': function(){ return '<span>找不到相关的商品分类，<a href="{url('admin/store/cate')}">添加商品分类</a></span>' }},
}));

$('#addform').submit(function(e) {
  var data = LIVE.component.form.getData($(this));
  var flowers = parseInt('0' + data['flowers']), lifetime = parseInt('0' + data['lifetime']);
  if (!data['image']) { return alert('请上传商品图片') || e.preventDefault();}
  if (!data['name']) { return alert('请填商品标题') || e.preventDefault();}
  if (!lifetime) { return alert('请填消耗时长') || e.preventDefault();}
  if (!flowers) { return alert('请填鲜花收益') || e.preventDefault();}
  if (!data['cate_id']) { return alert('请选择商品类目') || e.preventDefault();}
  return true;
});

</script>

</html>

